<?php 
include_once ("common.php");
require_once CLASS_PATH."file.class.php";
if(empty($action)) $action="";
if(empty($imgwidthValue)) $imgwidthValue='';
if(empty($imgheightValue)) $imgheightValue='';

if(empty($imgwidth)) $imgwidth='400';
if(empty($imgheight)) $imgheight='300';

if(empty($imgsrcValue)) $imgsrcValue="";
if(empty($imgurl)) $imgurl="";


if($_POST[action] == upimgsumbit ){


	if(empty($_FILES['Photo']['name'])){
		showjava("对不起，没有上传文件！");
		exit();
	}

	if($_FILES['Photo']['size'] ==0){
		showjava("对不起，图片文件的字节数为0！");
		exit();
	}

	if(!@is_uploaded_file($_FILES['Photo']['tmp_name'])){
		showjava("对不起，文件上传失败！");
		exit();
	}

	if($_FILES['Photo']['size'] > ($sys_info['filesize']*1024*1024)){
		showjava("对不起，你上传的文件不得超过" . $sys_info['filesize'] . "M！");
		exit;
	}

	if(!file_type($_FILES['Photo']['name'],$sys_info['filetype']))
	{
		$FileType = explode(".", $_FILES['Photo']['name']);
		showjava("对不起，请不要上传" . end($FileType) . "格式的文件！");
		exit();
	}

	$FileType = explode(".", $_FILES['Photo']['name']);
	$PhotoName = 'img' . Date('d'.time()) . '.' . end($FileType);
	$Html = new Html();
	$Html->createdir(SYS_PATH . $sys_info[uploaddir] .'/images/'. Date('Y',time()).'/'.Date('m',time()));

	$SavePath = SYS_PATH . $sys_info[uploaddir] .'/images/'. Date('Y',time()).'/'.Date('m',time()) . '/'. $PhotoName;
	$SaveUrl = $sys_info[url] .'/'. $sys_info[uploaddir] .'/images/'. Date('Y',time()).'/'.Date('m',time()) . '/' . $PhotoName;

	$Photo = $_FILES['Photo']['tmp_name'];

	if(@copy($Photo,$SavePath)){
		//showjava("文件上传成功！文件被重命名为$PhotoName");
		$imgsrcValue = $SaveUrl;
	}
}
?>
<HTML>
<HEAD>
<title>插入图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
td{font-size:10pt;}
</style>
<script language=javascript>
var oEditor	= window.parent.InnerDialogLoaded() ;
var oDOM		= oEditor.FCK.EditorDocument ;
var FCK = oEditor.FCK;


function SeePic(imgid,fobj)
{
   if(!fobj) return;
   if(fobj.value != "" && fobj.value != null)
   {
     var cimg = document.getElementById(imgid);
     if(cimg) cimg.src = fobj.value;
   }
}
function UpdateImageInfo()
{
	var imgsrc = document.form1.txtUrl.value;
	if(imgsrc!="")
	{
	  var imgObj = new Image();
	  imgObj.src = imgsrc;
	  document.form1.himgheight.value = imgObj.height;
	  document.form1.himgwidth.value = imgObj.width;
	  document.form1.txtHeight.value = imgObj.height;
	  document.form1.txtWidth.value = imgObj.width;
  }
}
function UpImgSizeH()
{
   var ih = document.form1.himgheight.value;
   var iw = document.form1.himgwidth.value;
   var iih = document.form1.txtHeight.value;
   var iiw = document.form1.txtWidth.value;
   if(ih!=iih && iih>0 && ih>0 && document.form1.autoresize.checked)
   {
      document.form1.txtHeight.value = Math.ceil(iiw * (iih/ih));
   }
}
function UpImgSizeW()
{
   var ih = document.form1.himgheight.value;
   var iw = document.form1.himgwidth.value;
   var iih = document.form1.txtHeight.value;
   var iiw = document.form1.txtWidth.value;
   if(iw!=iiw && iiw>0 && iw>0 && document.form1.autoresize.checked)
   {
      document.form1.txtWidth.value = Math.ceil(iih * (iiw/iw));
   }
}
</script>
<script src="common/fck_dialog_common.js" type="text/javascript"></script>
<script src="fck_image/fck_image.js" type="text/javascript"></script>
</head>
<body scroll="no" style="OVERFLOW: hidden">
<body bgcolor="#EBF6CD" leftmargin="4" topmargin="2">
<form enctype="multipart/form-data" name="form1" id="form1" method="post">
<input name="action" type="hidden" value="upimgsumbit">
<input type="hidden" name="himgheight" value="<?php echo $imgheightValue?>">
<input type="hidden" name="himgwidth" value="<?php echo $imgwidthValue?>">
  <table width="100%" border="0">
    <tr height="20"> 
      <td colspan="3">
      <fieldset>
        <legend>图片属性</legend>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="65" height="25" align="right"><span fckLang="DlgImgURL">URL</span></td>
            <td colspan="2">
            <input type="text" id="txtUrl" style="WIDTH:80%" onChange="SeePic('picview',this);" value="<?php echo $imgsrcValue ?>" size="8" name="pic"></td>
          </tr>
          <tr> 
            <td height="25" align="right"><span fckLang="DlgImgWidth">Width</span></td>
            <td colspan="2" nowrap>
            <input type="text" size="8" id="txtWidth" value="<?php echo $imgwidthValue?>" onChange="UpImgSizeW()">
			
              &nbsp;&nbsp; <span fckLang="DlgImgHeight">Height</span>
              <input type="text" size="3" id="txtHeight"  value="<?php echo $imgheightValue?>" onChange="UpImgSizeH()"> 
              <input type="button" name="Submit" value="原始" class="binput" style="width:40" onClick="UpdateImageInfo()">
              <input name="autoresize" type="checkbox" id="autoresize" value="1" checked>
              自适应</td>
          </tr>
          <tr> 
            <td height="25" align="right">边框：</td>
            <td colspan="2" nowrap><input name="border" type="text" id="border" size="4" value="0"></td>
          </tr>
          <tr> 
            <td height="25" align="right"><span fckLang="DlgImgAlt">Short Description</span>：</td>
            <td width="166" nowrap><input id="txtAlt" style="width: 100%" type="text"></td>
            <td width="155" align="center" nowrap>&nbsp;</td>
          </tr>
		  <tr>
            <td height="25" align="right"><span fckLang="DlgImgAlign">Align</span></td>
            <td nowrap>
            <select id="cmbAlign">
              <option value="" selected></option>
              <option fckLang="DlgImgAlignLeft" value="left">Left</option>
              <option fckLang="DlgImgAlignAbsBottom" value="absBottom">Abs Bottom</option>
              <option fckLang="DlgImgAlignAbsMiddle" value="absMiddle">Abs Middle</option>
              <option fckLang="DlgImgAlignBaseline" value="baseline">Baseline</option>
              <option fckLang="DlgImgAlignBottom" value="bottom">Bottom</option>
              <option fckLang="DlgImgAlignMiddle" value="middle">Middle</option>
              <option fckLang="DlgImgAlignRight" value="right">Right</option>
              <option fckLang="DlgImgAlignTextTop" value="textTop">Text Top</option>
              <option fckLang="DlgImgAlignTop" value="top">Top</option>
            </select></td>
            <td align="right" nowrap>&nbsp;            </td>
          </tr>
        </table>
        </fieldset>        </td>
    </tr>
    <tr height="25"> 
      <td colspan="3" nowrap> <fieldset>
        <legend>上传新图片</legend>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr height="30"> 
            <td align="right" nowrap>　新图片：</td>
            <td colspan="2" nowrap><input name="Photo" type="file" id="Photo" onChange="SeePic('picview',this);" style="height:22" class="binput"> 
              &nbsp; <input type="submit" name="picSubmit" id="picSubmit" value=" 上 传  " style="height:22" class="binput"></td>
          </tr>
          <tr height="30"> 
            <td align="right" nowrap>&nbsp;</td>
            <td colspan="2" nowrap></td>
          </tr>
        </table>
        </fieldset></td>
    </tr>
  </table>
</form>
</body>
</HTML>
